package com.codrim.cs.data.server.dao.entity;

import com.codrim.cs.data.rpc.dto.param.StatisticDataDTO;
import com.codrim.cs.data.server.dao.entity.unique.key.StatCsAdvAffUniqueKey;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
 * @author Liang.Zhuge
 */
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
public class StatCsAdvAffDO extends AbstractStatCsEntity<StatCsAdvAffUniqueKey> {
    private Integer id;
    private Integer advertiserId;
    private Integer affiliateId;

    private Integer sdate;
    private String symbol;

    private Long click;
    private Long uclick;
    private Long gc;
    private Long conversion;
    private Float aprice;
    private Float pprice;
    private Long caps;
    private Long sc;

    /**
     * 自己公司为广告主设置的商务经理ID
     */
    private Integer advAdvertiserManagerId;
    /**
     * 自己公司为渠道设置的渠道经理ID
     */
    private Integer advAffiliateManagerId;
    private Integer advAdvertiserManagerDepartmentId;
    private Integer advAffiliateManagerDepartmentId;

    public StatCsAdvAffDO(int sdate, StatisticDataDTO dto) {
        super();
        setSdate(sdate);
        setSymbol(dto.getCurrencySymbol());
        setAdvertiserId(dto.getAdvId());
        setAffiliateId(dto.getAffId());
        setAdvAdvertiserManagerId(dto.getAdvAdvertiserManagerId());
        setAdvAdvertiserManagerDepartmentId(dto.getAdvAdvertiserManagerDepartmentId());
        setAdvAffiliateManagerId(dto.getAdvAffiliateManagerId());
        setAdvAffiliateManagerDepartmentId(dto.getAdvAffiliateManagerDepartmentId());
    }


    @Override
    public void plus(AbstractStatCsEntity source) {
        if (!(source instanceof StatCsAdvAffDO)) {
            throw new IllegalArgumentException();
        }

        StatCsAdvAffDO cSource = (StatCsAdvAffDO) source;
        this.click = add(this.click, cSource.click);
        this.uclick = add(this.uclick, cSource.uclick);
        this.gc = add(this.gc, cSource.gc);
        this.conversion = add(this.conversion, cSource.conversion);
        this.aprice = add(this.aprice, cSource.aprice);
        this.pprice = add(this.pprice, cSource.pprice);
        this.caps = add(this.caps, cSource.caps);
        this.sc = add(this.sc, cSource.sc);
    }

    @Override
    public void plus(StatisticDataDTO cSource) {
        this.click = add(this.click, cSource.getClick());
        this.uclick = add(this.uclick, cSource.getUclick());
        this.gc = add(this.gc, cSource.getGc());
        this.conversion = add(this.conversion, cSource.getConversion());
        this.aprice = add(this.aprice, cSource.getAccessPrice());
        this.pprice = add(this.pprice, cSource.getPutPrice());
        this.caps = add(this.caps, cSource.getCaps());
        this.sc = add(this.sc, cSource.getSc());
    }

    @Override
    public StatCsAdvAffUniqueKey createUniqueKey() {
        return new StatCsAdvAffUniqueKey(sdate, advertiserId, affiliateId, symbol,advAdvertiserManagerId, advAffiliateManagerId);
    }

}
